package ViewEngineAction;

use strict;

use Athena::WebAPI::Response;
use Athena::EngineView;
use Athena::Engine;

sub execute {
  my $stInvocant = shift(@_);
  my $rRequest = shift(@_);
  my $rConn = shift(@_);
  my $rResponse = undef;
  my %hParams = ( @_ );
  my $stParams = \%hParams;
  my $stActionName = 'ViewEngineAction';
  my $stErrMsg = "";
  $rRequest->action($stActionName);
  my $stAction = $rRequest->param($stActionName);
  my $stLb = $rRequest->cookie('AthenaEngineUrl') 
    || $rRequest->cookie('AthenaEngineHost') 
      . ":" . $rRequest->cookie('AthenaEnginePort');

  my $rEngine = Athena::Engine->new($rConn);
  $rEngine->refresh();

  my $rHiddenFields = {
		       $rRequest->getActionParam() => $rRequest->action(),
		       $stActionName => '',
		      };
  my $rView = EngineView->new('lb' => $stLb,
			      'err_msg' => $stErrMsg,
			      'hidden_fields' => $rHiddenFields,
			      'action_name' => $stActionName,
			      'body_style' => $stParams->{body_style},
			      'table_style' => $stParams->{table_style},
			      'engine' => $rEngine
			     );

  $rResponse = Response->new($rView);
  
  return $rResponse;
}

1;
